package controllers

import (
	"OPS_TEMPLATE/models"
	"github.com/astaxie/beego"
)

type MainController struct {
	beego.Controller
}

func (this *MainController) Get() {
	ses := this.GetSession("roleName")
	if ses == nil {
		this.TplName = "common/_login.html"
		return
	}
	beego.Debug(ses)
	var menu *models.Menu
	this.Data["topmenu"] = menu.GetAllmenus(1)
	this.TplName = "index.html"
}

func (this *MainController) Login() {
	beego.Debug("aaaaa")
	var user models.User
	user.Username = this.GetString("Username")
	user.Password = this.GetString("Password")
	if user.Authenticate() {
		this.SetSession("roleName", "test")
		this.TplName = "index.html"
	}
	this.TplName = "common/_login.html"
}

func (this *MainController) Logout() {
	this.DelSession("roleName")
	this.TplName = "common/_login.html"
}
